package sourismobile.MIDlet.module;

import java.io.DataOutputStream;
import java.io.IOException;

import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;

import sourismobile.MIDlet.core.SourisMobileControler;

public class MousseCanvas extends Canvas {
	
	DataOutputStream out;
	int keyPressed;
	SourisMobileControler midlet;
	
	int width, height;
	int bgColor   = 0xffffff;
	int textColor = 0x000000;
	
	public MousseCanvas(DataOutputStream out, SourisMobileControler midlet) {
		super();
		this.out = out;
		this.midlet = midlet;
		Display.getDisplay(midlet).setCurrent(this);
		//setFullScreenMode(true);
		width  = this.getWidth();
		height = this.getHeight();
	}

	protected void paint(Graphics g) {

		g.setColor(bgColor);
		g.fillRect(0, 0, width, height);
			
		Font f = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_LARGE);
		g.setFont(f);
		
		g.setColor(textColor);
		g.drawString("[" + keyPressed + "]", width/2, height/2, Graphics.BASELINE|Graphics.HCENTER);
	}

	protected void keyPressed(int keyCode) {
		keyPressed = this.getGameAction(keyCode);
		try {
			out.writeInt(keyPressed);
		} catch (IOException e1) {
			e1.printStackTrace();
		}		
		
		if (keyPressed == 0) {
			midlet.setModule(0, "");
			midlet.back();
		}
		
		repaint();
		
	}
}
